<?php
/* 
* @Title:  [前台用户个人中心控制器]
* @Author: {chenlei} [chenleib5@126.com]
* @Date:   2014-04-21 13:29:30
* @Last Modified by:   Administrator
* @Last Modified time: 2014-04-27 15:46:03
* @Copyright:  [hn7m.com]
*/
class UserControl extends CommonControl{
	private $orderModel=NULL;
	private $userModel=NULL;
	private $listModel=NULL;
	/**
	 * [__init 自动加载模型]
	 * @return [type] [description]
	 */
	public function __init(){
		parent::__init();
		$this->orderModel=K('Order');
		$this->userModel=K('User');
		$this->listModel=K('OrderList');
	}

	public function index(){
		$uid=Q('session.uid');
		
		$count=array(
			'o'=>$this->orderModel->get_num(array('ostate'=>1,'qm_user_uid'=>$uid)),
			'p'=>$this->orderModel->get_num(array('ostate'=>3,'qm_user_uid'=>$uid)),
			'c'=>$this->orderModel->get_num(array('ostate'=>4,'qm_user_uid'=>$uid))
			);
		$this->assign('count',$count);//分配计数

		$order=$this->orderModel->get_data(array('qm_user_uid'=>$uid));
		$this->assign('order',$order);//分配订单
		
		$user=$this->userModel->get_one_data(array('uid'=>$uid));
		$this->assign('user',$user);//分配用户信息

		$this->display();
	}
	/**
	 * [ajax_recevied_goods 异步收货]
	 * @return [type] [description]
	 */
	public function ajax_recevied_goods(){
		if(IS_AJAX){
			$oid=Q('post.oid',0,'intval');
			if($this->orderModel->update_state($oid,4)){
				$return=array(
					'state'		=>1,
					'message'	=>'操作成功!'
					);
			}else{
				$return=array(
					'state'		=>0,
					'message'	=>'收货失败,可能是权限不够'
					);
			}

			echo json_encode($return);die();
		}
	}
	/**
	 * [ajax_show_ordergoods 异步显示订单中的商品]
	 * @return [type] [description]
	 */
	public function ajax_show_ordergoods(){
		if(IS_AJAX){
			$oid=Q('post.oid',0,'intval');
			$goods=$this->listModel->get_data(array('qm_order_oid'=>$oid));
			foreach ($goods as $key => $value) {
				$goods[$key]['gname']=K('Goods')->get_onedate_value($value['qm_goods_gid'],'gname');
				$goods[$key]['gthumb_img']=K('Goods')->get_onedate_value($value['qm_goods_gid'],'gthumb_img');
			};
			echo json_encode($goods);die();
		}
	}
}
?>